package cn.edu.zut.dao;

import cn.edu.zut.domain.Message;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface MessageDao {
    //根据userId查询通知，并根据_id降序排列
    @Select("select * from message where userId = #{userId} order by _id desc")
    public List<Message> findByUserId(String userId);
    //添加通知
    @Select("insert into message(_id, userId, title, content, time, vis) values(#{_id}, #{userId}, #{title}, #{content}, #{time}, #{vis})")
    public void add(Message message);
    //根据_id删除通知
    @Delete("delete from message where _id = #{_id}")
    public void deleteById(int _id);
    //根据_id查询通知
    @Select("select * from message where _id = #{_id}")
    public Message findById(int _id);
    //更新通知
    @Update("update message set userId = #{userId}, title = #{title}, content = #{content}, time = #{time}, vis = #{vis} where _id = #{_id}")
    public void update(Message message);
    //根据userId和vis查询通知
    @Select("select * from message where userId = #{arg0} and vis = #{arg1}")
    public List<Message> findAllNoVis(String userId,String vis);
    //查询所有通知
    @Select("select * from message order by _id")
    public List<Message> findAll();
}
